package com.bckj.fastboot.iot.biz.mq.consumer;

import com.bckj.fastboot.iot.biz.service.IotDeviceLifecycleService;
import com.bckj.fastboot.iot.common.constant.IotMQConstants;
import com.bckj.fastboot.iot.common.dto.ctx.IotDeviceContext;
import com.bckj.fastboot.iot.common.dto.msg.IotDeviceMessage;
import com.bckj.fastboot.iot.common.mq.consumer.IotDeviceMessageConsumer;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

/**
 * IotDeviceMessageConsumerImpl
 *
 * @author wfc
 **/
@Component
public class IotDeviceMessageConsumerImpl implements IotDeviceMessageConsumer {

    @Resource
    private IotDeviceLifecycleService iotDeviceLifecycleService;

    @Override
    public void onMessage(IotDeviceMessage message) {
        switch (message.getTag()) {
            case IotMQConstants.IOT_DEVICE_HEARTBEAT_TAG -> {
                // 处理设备心跳
                var ctx = new IotDeviceContext();
                ctx.setDevCode(message.getDevCode());
                ctx.setHeartbeatTime(message.getHeartbeatTime());
                iotDeviceLifecycleService.onDeviceHeartbeat(ctx);
            }
        }
    }
}
